function [ dataVals ] = alignIndeces( dataVals, startIdx, endIdx )
% Indexes the ECG start and end points based on the zero axis to avoid
% dimension mismatches.

try
    
    dataVals = dataVals(startIdx:endIdx, :);

catch ME
    
    % Pads end ECG values to compensate for discontinuities or mismatch at
    % the end
    if dataVals(endIdx) == 0
        
        dataVals(length(dataVals + 1):endIdx, 2) = mode(dataVals(find(dataVals(:, 2)>0), 2));
    
    end
    
    % Pads beginning ECG values to compensate for discontinuities or mismatch
    % at the beginning
    
    if dataVals(startIdx, 2) == 0
        
        zeroVals = dataVals(dataVals(:, 2) == 0, :);
        
        maxIdx = max(zeroVals(:, 1));
        
        dataVals(startIdx:maxIdx, 2) = mode(dataVals(find(dataVals(:, 2)>0), 2));
        
        
    end
    
        
end
    


dataVals(dataVals(:, 2) == 0, :) = [];

dataVals(:, 1) = 1:length(dataVals);


end

